﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MISAPP.Classify.DataAccess;
using System.Data;
using MISAPP.MISInterface;

namespace MISAPP.Classify.Service
{
    public class Service_CFG002
    {
        protected DA_CFG002 da = null;
        protected DA_CFG002 DA
        {
            get
            {
                if (da == null)
                {
                    da = new DataAccess.DA_CFG002();
                }
                return da;
            }
        }

        public System.Data.DataTable GetSummaryData(System.Collections.ArrayList p_list)
        {
            string date1 = p_list[0] as string;
            List<string> dates = p_list[1] as List<string>;
            List<DataTable> dtList = p_list[2] as List<DataTable>;
            bool account = Convert.ToBoolean( p_list[3]) ;
            DA.CreateMISBALString(dtList);            
            DataTable resultDT = DA.GetSummaryData(date1,dates.ToArray(),account);

            //int pos = 0;
            //for (int i = 1; i <= dtList.Count; i++)
            //{
            //    DataRow[] xx = (from xxx in resultDT.AsEnumerable()
            //             where xxx.Field<string>("OPT") == "1"
            //             select xxx).ToArray<DataRow>() ;
            //    DataTable source = dtList[i];
            //    pos = 0;
            //    foreach(DataRow row in xx)
            //    {
            //        DataRow[] sourceRow = (from xrow in source.AsEnumerable()
            //                             where xrow.Field<string>("產品名稱") == row[0].ToString()
            //                             select xrow).ToArray<DataRow>();
            //        xx[pos]["MIS餘額"] = Convert.ToInt64(sourceRow[0]["MIS餘額"].ToString());
            //        pos++;
            //    }
            //}

            
            

            
            return resultDT;
        }

        public System.Data.DataTable GetEmptyBALTable()
        {
            return DA.GetEmptyBALTable();
        }
    }
}
